var app = getApp()
Page({
  data: {
    motto: 'Hello World',
    userInfo: {}
  },
  onLoad: function () {
    console.log('onLoad')

  },
  setLoading: function () {
    wx.login({
      success: function (res) {
        console.log('登录凭证：', res.code)
        if (res.code) {
          //发起网络请求
          wx.request({
            url: 'https://xcx.aijinrun.com/getopenid-wxpay.php',
            data: {
              code: res.code
            },
            success: function (res) {
              console.log('这里是getopenid-wxpay.php返回的数据：', res.data)


              wx.request({
                url: 'https://xcx.aijinrun.com/MiniProgram/payfee.php',
                data: {
                  openid: res.data,
                  fee: '0.01' //商品价格
                },
                success: function (res) {
                  console.log(res);
                  console.log(res.data.timeStamp);
                  console.log('调起支付');

                  wx.requestPayment({
                    'timeStamp': res.data.timeStamp,
                    'nonceStr': res.data.nonceStr,
                    'package': res.data.package,
                    'signType': 'MD5',
                    'paySign': res.data.paySign,
                    'success': function (res) {
                      console.log(res);

                      wx.showToast({
                        title: '支付成功',
                        icon: 'success',
                        duration: 3000
                      });

                    },
                    'fail': function (res) {
                      //console.log(res);
                      console.log('用户取消了支付');
                      wx.showModal({
                        title: "提示",
                        content: "支付取消或失败",
                        showCancel: false,
                        confirmText: "确定"
                      })
                    },
                    'complete': function (res) {
                      console.log('complete');
                    }
                  });

                },
                fail: function (res) {
                  console.log(res.data)
                }

              })


            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })



  }
})